#关闭防火墙
systemctl stop firewalld.service
systemctl disable firewalld.service
#关闭交换内存，kubelet不支持开启swap分区时使用
swapoff -a && sed -i '/swap/s/^\(.*\)$/#\1/g' /etc/fstab
#设置 /etc/selinux/config中 SELINUX=disabled
sed -i 's/SELINUX=permissive/SELINUX=disabled/g' /etc/selinux/config

#关闭交换空间,系统OOM 才允许使用
echo 'vm.swappiness = 0
#开启OOM
vm.panic_on_oom=0
#有了它,ipvs才能进行转发
net.ipv4.ip_forward=1
net.ipv4.tcp_tw_recycle=0
net.ipv4.vs.conntrack=1
#关闭ipv6
net.ipv6.conf.all.disable_ipv6=1
net.bridge.bridge-nf-call-iptables=1
net.bridge.bridge-nf-call-ip6tables=1
#开启文件句柄数目
fs.file-max=52706936
fs.nr_open=52706936
net.netfilter.nf_conntrack_max=2310720' > /etc/sysctl.d/kubernetes.conf
sysctl --system

#加载必要模块
modprobe br_netfilter
echo 1 > /proc/sys/net/bridge/bridge-nf-call-iptables

#设置源
echo '[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg' > /etc/yum.repos.d/kubernetes.repo

#install containerd
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo 
yum install containerd.io-1.4.6 -y
containerd config default > /etc/containerd/config.toml
sed -i "s#k8s.gcr.io#registry.cn-hangzhou.aliyuncs.com/google_containers#g"  /etc/containerd/config.toml
sed -i "s#https://registry-1.docker.io#https://registry.cn-hangzhou.aliyuncs.com#g"  /etc/containerd/config.toml
sed -i '/containerd.runtimes.runc.options/a\ \ \ \ \ \ \ \ \ \ \ \ SystemdCgroup = true' /etc/containerd/config.toml
systemctl daemon-reload
systemctl enable containerd
systemctl restart containerd
crictl config runtime-endpoint /run/containerd/containerd.sock

#install kubernetes
yum remove kubeadm kubelet kubectl -y
yum install -y kubelet-1.20.5 kubeadm-1.20.5 kubectl-1.20.5
systemctl enable kubelet.service

#安装helm
wget https://get.helm.sh/helm-v3.5.3-linux-amd64.tar.gz
tar -xf helm-v3.5.3-linux-amd64.tar.gz
cp -a linux-amd64/helm /usr/local/bin/
chmod a+x /usr/local/bin/helm
#添加stable仓库
helm repo add stable https://charts.helm.sh/stable

#主节点执行
#cp kube-vip.yaml /etc/kubernetes/manifests/
#kubeadm init --config=kubeadm-config.yaml --upload-certs | tee kubeadm.log
